//! Copyright 2012 NTH Technology, Inc.
//! All rights reserved
//!
#include "stm32f10x.h"
#include "SysTick.h"
#include "Config.h"

extern "C"  {
    volatile U32 s_TickCnt;
    void SysTick_Handler(void)
    {
        s_TickCnt++;
    }
};

void cSysTick::InitReset()
{
    SysTick_Config(SystemCoreClock / cConfig::SYSTEM_TICK_INTERRUPT);
    s_TickCnt = 0;
}

bool cSysTick::CheckTimeOut()
{
    U32 timeCnt;

    if (mTimeBase < s_TickCnt)
    {
        timeCnt = s_TickCnt - mTimeBase;
    }
    else
    {
        timeCnt = s_TickCnt + (~mTimeBase) + 1;
    }

    return ( (mTimeout <= timeCnt)? true: false );
}

